Interview Questions and Answers - Order By Rating Q31. Can we have try and catch blocks within finally ? Core Java
Ans. Yes, if we have a cleanup code that might throw an exception in the finally block, then we can have a try-catch block Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   exceptions   exception handling   finally   try   catch   yesnoRelated Questions Explain throw, throws , try and catch in Java ? How can we make sure that a code segment gets executed even in case of uncatched exceptions ? Is it necessary that each try block to be followed by catch block ? How does a try statement determine which catch clause should be used to handle an exception? Can finally block be used without catch ? Will finally be called always if all code has been kept in try block ? Which of the following is not possible ? Can we have try statement without catch? If try statement contains return will the finally block be executed? What happens if there is an exception inside finally block? How can we catch an exception thrown by another thread ? Q32. Tell me something about AssertionError ? Core Java
Ans. AssertionError is actually a fatal fault or a bug in the program. We may not like to continue program , request or thread execution if this error occurs as this condition is the assumption to continue further execution. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   error   exceptions   exception handling   assertion error   assertionerrorRelated Questions Very Frequently asked. Q33. Explain throw, throws , try and catch in Java ? Core Java
Ans. throw is used to re throw an exception.throws is used to declare that the method throws the respective exceptions.try block is used to identify if the respective block has thrown any exception.catch is used to catch the exception that has been thrown by the respective try block. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   exception handling   throw   throws   try   catch Asked in 5 Companies basic   frequent Related Questions What are the ways to avoid LazyInitializationException ? How compiler handles the exceptions in overriding ? What things should be kept in mind while creating your own exceptions in Java? Difference between Checked and Unchecked exceptions ? Explain java.lang.OutOfMemoryError ? When do you get ClassCastException?
or
What is ClassCastException ? If you are given a choice to implement the code to either Insert a Record or Update if already exist, Which approach will you follow ? What is ConcurrentModificationException ? What will happen if we don't have termination statement in recursion ? Q34. In Case a method is declared to throw an exception , We can only use a call to that method if ... Core Java
a. We use the call within try block and catch the exception b. We declare that the method is expected to throw the exception using throws c. Both 1 and 2 d. Either 1 or 2Ans.d. Either 1 or 2
Q35. Which of the following is true ? Core Java
a. throw and throws are used to throw an exception b. throw is used to throw an exception whereas throws is a declaration that the method can throw the exception c. throws is used to throw an exception whereas throw is a declaration that the method can throw the exception d. throw and throws are used to declare that an exception can be thrown by the methodAns.b. throw is used to throw an exception whereas throws is a declaration that the method can throw the exception
Q36. throws is a declaration that the ..... is expected to throw an exception ? Core Java
a. Variable b. Method c. Class d. InterfaceAns.b. Method